/*
 *接口编写处...
*如果接口需要做Action的权限验证，请在Action上使用属性
*如: [ApiActionPermission("Mds_LogisticTask",Enums.ActionPermissionOptions.Search)]
 */
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Http;
using DGZImp.MdsProject.DomainModels;
using DGZImp.MdsProject.IServices;
using DGZImp.Core.Filters;
using DGZImp.Core.Utilities.Response;
using DGZImp.Core.Utilities;
using Microsoft.AspNetCore.Authorization;

namespace DGZImp.MdsProject.Controllers
{
    public partial class Mds_LogisticTaskController
    {
        private readonly IMds_LogisticTaskService _service;//访问业务代码
        private readonly IHttpContextAccessor _httpContextAccessor;

        [ActivatorUtilitiesConstructor]
        public Mds_LogisticTaskController(
            IMds_LogisticTaskService service,
            IHttpContextAccessor httpContextAccessor
        )
        : base(service)
        {
            _service = service;
            _httpContextAccessor = httpContextAccessor;
        }

        /// <summary>
        /// 手动启动物流任务
        /// </summary>
        /// <param name="taskId"></param>
        /// <returns></returns>
        [HttpPost("StartLogisticTask")]
        public async Task<ApiResponse<string>> StartLogisticTask([FromQuery] long? taskId)
        {
            await Service.StartLogisticTask(taskId);
            return ApiRes.Success("");
        }

        /// <summary>
        /// 手动取消物流任务
        /// </summary>
        /// <param name="taskId"></param>
        /// <returns></returns>
        [HttpPost("CancleLogisticTask")]
        public async Task<ApiResponse<string>> CancleLogisticTask([FromQuery] long? taskId)
        {
            await Service.CancleLogisticTask(taskId);
            return ApiRes.Success("");
        }

        /// <summary>
        /// 强制完成物流任务
        /// </summary>
        /// <param name="taskId"></param>
        /// <returns></returns>
        [HttpPost("ForceCompletLogisticTask")]
        public async Task<ApiResponse<string>> ForceCompletLogisticTask([FromQuery] long? taskId)
        {
            await Service.ForceCompletLogisticTask(taskId);
            return ApiRes.Success("");
        }

        /// <summary>
        /// 手动完成物流明细任务
        /// </summary>
        /// <param name="taskId"></param>
        /// <param name="taskNo"></param>
        /// <returns></returns>
        [HttpPost("FinishLogisticDetailTask")]
        public async Task<ApiResponse<string>> FinishLogisticDetailTask([FromQuery] long? taskId, int? taskNo)
        {
            await Service.FinishLogisticDetailTask(taskId, taskNo);
            return ApiRes.Success("");
        }

        /// <summary>
        /// 自动下发物流任务，并处理任务完成数据
        /// </summary>
        /// <returns></returns>
        [ApiTask]
        [HttpPost("AutoSendAndCompleteLogisticTask")]
        public async Task<ApiResponse<string>> AutoSendAndCompleteLogisticTask()
        {
            await Service.AutoCompleteLogisticTask();
            await Service.AutoSendLogisticTask();
            return ApiRes.Success("");
        }

        /// <summary>
        /// 生成空罐下线任务
        /// </summary>
        /// <param name="deviceId"></param>
        [AllowAnonymous]
        [HttpGet("GenerateCansOffLineTask")]
        public async Task GenerateCansOffLineTask(long deviceId, long? taskNo)
        {
            //await Service.ProcessConnectorTankTask(deviceId, taskNo);
            return;
        }
    }
}
